package io.bio;


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;


/**
 * 传统BIO模型的客户端
 */
public class BioClient {
    public static void main(String[] args) {
        // 连接一个服务端
        try(Socket socket = new Socket("127.0.0.1",9092);
            // 获取输入输出流
            OutputStream outputStream = socket.getOutputStream();
            InputStream inputStream = socket.getInputStream();) {
            // 向服务端写数据
            outputStream.write("hell bio server".getBytes());
            outputStream.flush();

            // 读取服务端响应的数据
            System.out.println("write over,wait for msg callback");
            byte[] bytes = new byte[1024];

            int len = inputStream.read(bytes);
            System.out.println(new String(bytes,0,len));

        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
